<?php
// +----------------------------------------------------------------------
// | 数据库迁移 - 创建模板数据库
// +----------------------------------------------------------------------

use think\facade\Db;
use think\migration\Migrator;

class CreateTemplate extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        // 表格模板表
        $table = $this->table('template_table', ['engine' => 'MyISAM', 'collation' => 'utf8mb4_bin', 'comment' => '表格模板表']);
        $table->addColumn('catalog_id', 'integer', ['null' => false, 'comment' => '分类ID'])
            ->addColumn('title', 'string', ['limit' => 100, 'null' => false, 'comment' => '标题'])
            ->addColumn('author', 'string', ['limit' => 100, 'null' => false, 'comment' => '作者'])
            ->addColumn('remark', 'string', ['limit' => 255, 'null' => false, 'comment' => '备注'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('status', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '状态'])
            ->addColumn('create_time', 'datetime', ['default' => NULL, 'comment' => '创建时间'])
            ->addColumn('update_time', 'datetime', ['default' => NULL, 'comment' => '更新时间'])
            ->create();

        // 表格模板分类表
        $table = $this->table('template_table_catalog', ['engine' => 'MyISAM', 'collation' => 'utf8mb4_bin', 'comment' => '表格模板分类表']);
        $table->addColumn('name', 'string', ['limit' => 100, 'null' => false, 'comment' => '分类名'])
            ->addColumn('remark', 'string', ['limit' => 255, 'default' => NULL, 'comment' => '备注'])
            ->addColumn('sort', 'integer', ['default' => 0, 'comment' => '排序'])
            ->addColumn('status', 'boolean', ['limit' => 1, 'default' => 1, 'comment' => '状态'])
            ->addColumn('create_time', 'datetime', ['default' => NULL, 'comment' => '创建时间'])
            ->addColumn('update_time', 'datetime', ['default' => NULL, 'comment' => '更新时间'])
            ->create();
    }
}
